package com.taotao.order.controller;

import com.taotao.common.core.domain.Result;
import com.taotao.order.domain.PaymentFlow;
import com.taotao.order.domain.request.OrderMessage;
import com.taotao.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @className: OrderController
 * @author: ZhangYuQi
 * @date: 2025/2/5 下午7:46
 * @Version: 1.0
 * @description:
 */
@RestController
@RequestMapping
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * @return
     * @Author ZhangYuQi
     * @Description 添加交易流水记录
     * @Date 下午7:53 2025/2/5
     * @Param [paymentFlow]
     */
    @PostMapping("addTransactionFlows")
    public Result addTransactionFlows(@RequestBody PaymentFlow paymentFlow) {
        orderService.addTransactionFlows(paymentFlow);
        return Result.success();
    }

    /**
     * @return
     * @Author ZhangYuQi
     * @Description 根据交易流水号查询交易流水记录
     * @Date 下午8:37 2025/2/5
     * @Param [tradeNo]
     */
    @PostMapping("findByTradeNo")
    public Result findByTradeNo(String tradeNo) {
        return Result.success(orderService.findByTradeNo(tradeNo));
    }

    /**
     * @return
     * @Author ZhangYuQi
     * @Description 用户下单
     * @Date 上午11:25 2025/2/7
     * @Param [orderMessage]
     */
    @PostMapping("placeAnOrder")
    public Result placeAnOrder(@RequestBody OrderMessage orderMessage) {

        // 在service中处理数据 实现异步下单
        //返回生成的订单号
      String orderNum= orderService.placeAnOrder(orderMessage);

        //返回结果
        return Result.success(orderNum, "下单中，请稍后查看订单状态");
    }


    /**
    * @Author ZhangYuQi
    * @Description 查询redis中的订单状态
    * @Date 上午10:38 2025/2/10
    * @Param [orderNum]
    * @return
    */
    @GetMapping("selectOrderStatusByOrderNum/{orderNum}")
    public Result selectOrderStatusByOrderNum(@PathVariable String orderNum) {
        return Result.success(orderService.selectOrderStatusByOrderNum(orderNum));
    }


}
